package com.zp.base.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.zp.base.entity.bo.ClinicScheduleBo;
import com.zp.base.entity.vo.ClinicScheduleVo;
import com.zp.base.service.IClinicScheduleService;
import com.zp.common.core.controller.BaseController;
import com.zp.common.core.entity.R;
import com.zp.common.core.validate.AddGroup;
import com.zp.common.core.validate.EditGroup;
import com.zp.common.excel.utils.ExcelUtil;
import com.zp.common.log.annotation.Log;
import com.zp.common.log.enums.BusinessType;
import com.zp.common.myBatis.core.page.PageQuery;
import com.zp.common.myBatis.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 出诊安排控制器
 * 前端访问路由地址为:/base/clinicSchedule
 *
 * @author zhang peng
 * @date 2023-01-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/clinicSchedule")
public class ClinicScheduleController extends BaseController {

    private final IClinicScheduleService iClinicScheduleService;

    /**
     * 查询出诊安排列表 (分页)
     */
    @SaCheckPermission("base:clinicSchedule:list")
    @GetMapping("/selectPage")
    public TableDataInfo<ClinicScheduleVo> selectPage (ClinicScheduleBo bo, PageQuery pageQuery) {
        return iClinicScheduleService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询出诊安排列表 (不分页)
     */
    @SaCheckPermission("base:clinicSchedule:list")
    @GetMapping("/list")
    public R<List<ClinicScheduleVo>> list (ClinicScheduleBo bo) {
        List<ClinicScheduleVo> list = iClinicScheduleService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出出诊安排列表
     */
    @SaCheckPermission("base:clinicSchedule:export")
    @Log(title = "出诊安排", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export (ClinicScheduleBo bo, HttpServletResponse response) {
        List<ClinicScheduleVo> list = iClinicScheduleService.queryList(bo);
        ExcelUtil.exportExcel(list, "出诊安排", ClinicScheduleVo.class, response);
    }

    /**
     * 获取出诊安排详细信息
     *
     * @param scheduleId 主键
     */
    @SaCheckPermission("base:clinicSchedule:query")
    @GetMapping("/{scheduleId}")
    public R<ClinicScheduleVo> getInfo (@NotNull(message = "主键不能为空") @PathVariable String scheduleId) {
        return R.ok(iClinicScheduleService.queryById(scheduleId));
    }

    /**
     * 新增出诊安排
     */
    @SaCheckPermission("base:clinicSchedule:add")
    @Log(title = "出诊安排", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add (@Validated(AddGroup.class) @RequestBody ClinicScheduleBo bo) {
        return toAjax(iClinicScheduleService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改出诊安排
     */
    @SaCheckPermission("base:clinicSchedule:edit")
    @Log(title = "出诊安排", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit (@Validated(EditGroup.class) @RequestBody ClinicScheduleBo bo) {
        return toAjax(iClinicScheduleService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除出诊安排
     *
     * @param scheduleIds 主键串
     */
    @SaCheckPermission("base:clinicSchedule:remove")
    @Log(title = "出诊安排", businessType = BusinessType.DELETE)
    @DeleteMapping("/{scheduleIds}")
    public R<Void> remove (@NotEmpty(message = "主键不能为空") @PathVariable String[] scheduleIds) {
        return toAjax(iClinicScheduleService.deleteWithValidByIds(Arrays.asList(scheduleIds), true) ? 1 : 0);
    }
}
